package servlet;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import service.NewsDaoService;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/deleteArticle")
public class DeleteArticle extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        NewsDaoService nds = new NewsDaoService();
        PrintWriter out = response.getWriter();
        String newsId = request.getParameter("newsId");
        String uid = request.getParameter("uid");
        int count = nds.deleteNews(newsId);
        String state = request.getParameter("state");
        if(count != 0){
            response.sendRedirect("articleByUid?uid="+uid+"&newsId="+newsId+"&state="+state);
            out.print("<script language='javascript'>alert('删除成功'); </script>");
        }else{
            out.print("<script language='javascript'>alert('删除失败'); window.location.href='./WinterTourism/material/template/Adminto/html/articleByUid.jsp'; </script>");
        }

    }
}
